<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>Cinema</title>
</h:head>
<h:body>

	<ui:include src="template.xhtml" />

	<p:tabView id="tabView">
		<p:tab id="tab1" title="Cinemas">
			<h:form>
				<p:dataTable var="cinema" value="#{cinemasBean.cinemas}">
					<p:column style="width:2%">
						<p:rowToggler />
					</p:column>
					<p:column headerText="Cinema">
						<h:outputText value="#{cinema.name}" />
					</p:column>

					<p:column headerText="Projections">
						<h:outputText value="#{cinema.projections.size()}" />
					</p:column>

					<p:rowExpansion>
						<h:panelGrid id="display" columns="2" cellpadding="4"
							style="width:600px;" styleClass=" ui-widget-content grid">
							<p:dataTable var="projection"
								value="#{projectionsBean.getProjectionsForCinema(cinema.id)}">
								<p:column headerText="Name">
									<h:commandLink
										action="#{projectionsBean.navigateToProjectionPage(projection.id)}"
										value="#{projection.movie.name}" includeViewParams="true">
										<f:param name="id" value="#{projection.id}" />
									</h:commandLink>
								</p:column>
								<p:column headerText="Rating">
									<h:outputText value="#{projection.movie.rating}" />
								</p:column>

								<p:column headerText="Date">
									<h:outputText value="#{projection.date}" />
								</p:column>

								<p:column headerText="Price">
									<h:outputText value="#{projection.price}" />
								</p:column>
							</p:dataTable>

						</h:panelGrid>

					</p:rowExpansion>
				</p:dataTable>
			</h:form>
		</p:tab>

		<p:tab rendered="#{UserSessionBean.user.role == 'user' }" id="tab2"
			title="My tickets">
			<h:form>
				<p:dataTable id="seatsTable" var="seat" value="#{seatsBean.seats}">

					<f:facet name="header">  
			            Expand rows to see detailed information  
			        </f:facet>

					<p:column style="width:2%">
						<p:rowToggler />
					</p:column>

					<p:column>
						<f:facet name="header">  
			                    Movie  
			            </f:facet>
						<h:outputText value="#{seat.projection.movie.name}" />
						<!-- since hibernate thiks it's samrt, movies was resolved to movy -->
					</p:column>

					<p:column>
						<f:facet name="header">  
			                    Cinema  
			            </f:facet>
						<h:outputText value="#{seat.projection.cinema.name}" />
					</p:column>

					<p:column>
						<f:facet name="header">  
			                    Date  
			            </f:facet>
						<h:outputText value="#{seat.projection.date}" />
					</p:column>

					<p:rowExpansion>
						<h:panelGrid id="display" columns="2" cellpadding="4"
							style="width:300px;" styleClass=" ui-widget-content grid">

							<h:outputText value="Seats:" />
							<h:outputText id="seatsCell"
								value="#{seatsBean.getAllSeatsForProjectionString(seat)}" />
							<h:outputText value="Price per seat:" />
							<h:outputText id="unitPriceCell" value="#{seat.projection.price}" />
							<h:outputText value="Total price:" />
							<h:outputText id="totalPriceCell"
								value="#{seatsBean.getAllSeatsForProjectionPrice(seat)}" />
						</h:panelGrid>

					</p:rowExpansion>
				</p:dataTable>
			</h:form>
		</p:tab>

		<p:tab id="tab3" title="Projections">
			<h:form>
				<p:dataTable var="projection" value="#{projectionsBean.projections}">
					<p:column headerText="Movie">
						<h:commandLink
							action="#{projectionsBean.navigateToProjectionPage(projection.id)}"
							value="#{projection.movie.name}" includeViewParams="true">
							<f:param name="id" value="#{projection.id}" />
						</h:commandLink>
					</p:column>

					<p:column headerText="Rating">
						<h:outputText value="#{projection.movie.rating}" />
					</p:column>

					<p:column headerText="Cinema">
						<h:outputText value="#{projection.cinema.name}" />
					</p:column>

					<p:column headerText="Date">
						<h:outputText value="#{projection.date}" />
					</p:column>

					<p:column headerText="Price">
						<h:outputText value="#{projection.price}" />
					</p:column>

				</p:dataTable>
			</h:form>
		</p:tab>

		<p:tab id="tab4" title="Movies">
			<h:form>
				<p:dataTable var="movie" value="#{moviesBean.movies}">
					<p:column style="width:2%">
						<p:rowToggler />
					</p:column>
					<p:column headerText="Movie">
						<h:commandLink
							action="#{moviesBean.navigateToMoviePage(movie.id)}"
							value="#{movie.name}" includeViewParams="true">
							<f:param name="id" value="#{movie.id}" />
						</h:commandLink>
					</p:column>
					<p:rowExpansion>
						<h:panelGrid id="display" columns="2" cellpadding="4"
							style="width:600px;" styleClass=" ui-widget-content grid">
							<p:dataTable var="projection"
								value="#{projectionsBean.getProjectionsForMovie(movie.id)}">
								<p:column headerText="Name">
									<h:commandLink
										action="#{projectionsBean.navigateToProjectionPage(projection.id)}"
										value="#{projection.movie.name}" includeViewParams="true">
										<f:param name="id" value="#{projection.id}" />
									</h:commandLink>
								</p:column>
								<p:column headerText="Rating">
									<h:outputText value="#{projection.movie.rating}" />
								</p:column>

								<p:column headerText="Cinema">
									<h:outputText value="#{projection.cinema.name}" />
								</p:column>

								<p:column headerText="Date">
									<h:outputText value="#{projection.date}" />
								</p:column>

								<p:column headerText="Price">
									<h:outputText value="#{projection.price}" />
								</p:column>
							</p:dataTable>

						</h:panelGrid>

					</p:rowExpansion>
				</p:dataTable>
			</h:form>
		</p:tab>

	</p:tabView>
	<p:messages id="messages" showDetail="true" autoUpdate="true"
		closable="true" />
</h:body>
</html>